package moe.oil.db;

import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import moe.oil.authority.PermissionInterceptor;
import moe.oil.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication(scanBasePackages = "moe.oil.*")
@EntityScan("moe.oil.db.entity")
@EnableFeignClients(defaultConfiguration = Config.class,basePackages = "moe.oil.*")
@EnableJpaRepositories(basePackages = "moe.oil.*")
@Setter(onMethod_ = @Autowired)
@Log4j2
public class DatabaseApplication  implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(DatabaseApplication.class, args);
    }

    private PermissionInterceptor permissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**");
    }
}

